<?php

namespace app\admin\model;

use think\Model;


class Projectcategory extends Model
{

    

    

    // 表名
    protected $name = 'project_category';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pname_text',
    ];

    public function getPnameTextAttr($value, $data)
    {
        if($data['pid'] == 0){
            return '顶级分类';
        }else{
            $row = self::where('id',$data['pid'])->find();
            return $row?$row['type_name']:'';
        }

        return '';
    }


    public function child()
    {
        return $this->hasOne(Projectcategory::class, 'id', 'pid');
    }







}
